module criteria

    use io, only: pos

    implicit none
    private

    public :: check

    contains

    subroutine check(i, j, k, l, rx, ry, rz, t0, die)

        real, intent(in) :: t0
        integer, intent(in) :: i, j, k, l
        real, intent(in) :: rx, ry, rz
        logical, intent(out) :: die

        real :: x, y, z

        die = .FALSE.

        ! Get particle position.
        call pos(i, j, k, l, rx, ry, rz, x, y, z)

        ! Write initial position.
        if (t0 == 0.0) then
            open(1, file='output/initial', access='append')
            write(1, *) x, y, z, i, j, k, l
            close(1)

            open(2, file='output/trajectory', access='append')
            write(2, *) '>'
            close(2)
        endif

        ! Write current position.
        open(2, file='output/trajectory', access='append')
        write(2, *) x, y, z, t0/(60*60*24*365.2425)
        close(2)

    end subroutine check

end module criteria
